home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15022 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: isonews.bbn.hp.com!hpbblb!news
  2. From: Matthias Dittrich <matti>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: help with program
  5. Date: 16 Apr 1996 08:16:14 GMT
  6. Organization: Hewlett-Packard Co.
  7. Message-ID: <4kvl0e$g4c@hpbblb.bbn.hp.com>
  8. References: <4kkgde$t2m@news.duke.edu>
  9. NNTP-Posting-Host: trabant.bbn.hp.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.07 9000/712)
  14. X-URL: news:4kkgde$t2m@news.duke.edu
  15.  
  16. kev@acpub.duke.edu (Kevin Daniels) wrote:
  17. >
  18. >Can anyone tell me why the following slice of code might be giving the 
  19. >unwanted behavior shown below?
  20. >
  21. >
  22. >void g_find_player1_human_move(void)
  23. >{
  24. >  int curr_row;
  25. >  int curr_col;
  26. >  int dest_row;
  27. >  int dest_col;
  28. >  int ok = 0;
  29. >  int val;
  30. >  int lcv;
  31. >
  32. >  while (!ok) {
  33. >
  34. >    printf("\n\nmove from row -> ");
  35. >    scanf("%d",&curr_row);
  36. >    printf("\n\nmove from col -> ");
  37. >    scanf("%d",&curr_col);
  38. >    printf("\n\nmove to row -> ");
  39. >    scanf("%d",&dest_row);
  40. >    printf("\n\nmove to col -> ");
  41. >    scanf("%d",&dest_col); 
  42. >    
  43. >    for(lcv = 1; lcv <=40; lcv ++) {
  44. >      if((RED_ALIVE.p[lcv].row_pos == curr_row) && (RED_ALIVE.p[lcv].col_pos == curr_col) && (RED_ALIVE.p[lcv].placed_on_board == 1)) {
  45. >    ok = g_is_legal_move(RED_ALIVE.p[lcv].row_pos,RED_ALIVE.p[lcv].col_pos,RED_ALIVE.p[lcv].row_pos,RED_ALIVE.p[lcv].col_pos,P1_TURN);
  46. >    if (ok) {
  47. >      g_make_move(RED_ALIVE.p[lcv].row_pos,RED_ALIVE.p[lcv].col_pos,RED_ALIVE.p[lcv].row_pos,RED_ALIVE.p[lcv].col_pos,P1_TURN);
  48. >    }
  49. >      }
  50. >    }
  51. >  }
  52. >}
  53. ..
  54. The function scanf() requires a '\n' character to accept input. You have to
  55. remove this character from the input stream. A call of fflush(stdin) before
  56. each scanf() should work.
  57.  
  58. Good luck,
  59. Matthais
  60.  
  61.